package application;

import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CosNaming.NameComponent;

import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextExtHelper;


public class NamingContextHierarchy {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		String[] orbconf = {args[0], args[1]};
		ORB orb = ORB.init(orbconf, null);
		
		Object objRef = orb.resolve_initial_references("NameService");
		NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
		
		NameComponent serN = new NameComponent("Servers", "");
		NameComponent DirserN = new NameComponent("DirectoryServers","");
		NameComponent LeafserN = new NameComponent("LeafServers","");
		NameComponent ClientN = new NameComponent("Clients","");
		
		NameComponent servs[] = {serN};
		NamingContext servers = ncRef.bind_new_context(servs);
		
		NameComponent clis[] = {ClientN};
		NamingContext clients = ncRef.bind_new_context(clis);
		
		NameComponent pathl[] = {LeafserN};
		NamingContext leafservers = servers.bind_new_context(pathl);
		
		NameComponent pathd[] = {DirserN};
		NamingContext directservers = servers.bind_new_context(pathd);

//		ncRef.unbind(servs);
	}

}
